package com.heo.music.player.controller;

import com.heo.music.player.auth.NeedLogin;
import com.heo.music.player.dto.input.LoginInput;
import com.heo.music.player.dto.input.ModifyPasswordInput;
import com.heo.music.player.dto.input.UserInfoInput;
import com.heo.music.player.dto.output.TokenOutput;
import com.heo.music.player.dto.output.UserInfoOutput;
import com.heo.music.player.service.AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * created on 2024-05-12 10:22
 *
 * @author 星天无极
 **/
@Api(tags = "认证接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class AuthController {

    private final AuthService authService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public TokenOutput login(@Valid @RequestBody LoginInput input) {
        return authService.login(input);
    }

    @ApiOperation("注册用户")
    @PostMapping("/register")
    public UserInfoOutput register(@Valid @RequestBody UserInfoInput input) {
        return authService.register(input);
    }

    @ApiOperation("修改密码")
    @NeedLogin
    @PostMapping("/modifyPassword")
    public void modifyPassword(@Valid @RequestBody ModifyPasswordInput input) {
        authService.modifyPassword(input);
    }

    @ApiOperation("获取用户信息")
    @NeedLogin
    @PostMapping("/userInfo")
    public UserInfoOutput getUserInfo() {
       return authService.getUserInfo();
    }
}
